package com.hb.podao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import com.core.BaseHibernateDAO;

/**
 * Data access object (DAO) for domain model class HbComment.
 * 
 * @see com.hb.podao.HbComment
 * @author MyEclipse Persistence Tools
 */

public class HbCommentDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(HbCommentDAO.class);

	// property constants
	public static final String NEEDID = "needid";

	public static final String PID = "pid";

	public static final String CONTENT = "content";

	public void save(HbComment transientInstance) {
		log.debug("saving HbComment instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(HbComment persistentInstance) {
		log.debug("deleting HbComment instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public HbComment findById(java.lang.Integer id) {
		log.debug("getting HbComment instance with id: " + id);
		try {
			HbComment instance = (HbComment) getSession().get(
					"com.hb.podao.HbComment", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(HbComment instance) {
		log.debug("finding HbComment instance by example");
		try {
			List results = getSession()
					.createCriteria("com.hb.podao.HbComment").add(
							Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding HbComment instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from HbComment as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByNeedid(Object needid) {
		return findByProperty(NEEDID, needid);
	}

	public List findByPid(Object pid) {
		return findByProperty(PID, pid);
	}

	public List findByContent(Object content) {
		return findByProperty(CONTENT, content);
	}

	public List findAll() {
		log.debug("finding all HbComment instances");
		try {
			String queryString = "from HbComment";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public HbComment merge(HbComment detachedInstance) {
		log.debug("merging HbComment instance");
		try {
			HbComment result = (HbComment) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(HbComment instance) {
		log.debug("attaching dirty HbComment instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(HbComment instance) {
		log.debug("attaching clean HbComment instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}